//
// Camera.cpp for  in /home/herpec_j/Dropbox/Projets/raytracer-2016/Sources/Cameras/
//
// Made by Jonathan
// Login   <ledey_l@epitech.net>
//
// Started on  Tue Sep 24 09:50:52 2013 Jonathan
// Last update Tue Sep 24 10:14:34 2013 Jonathan
//

#include		"Cameras/Camera.hpp"

namespace		Cameras
{
  Camera::Camera(void) : mEye(0, 0, 500), mLookAt(), mRollAngle(0), mUp(0, 1, 0), mU(1, 0, 0), mV(0, 1, 0), mW(0, 0, 1), mExposureTime(1)
  {
    return;
  }

  Camera::Camera(Camera const &rOther) : mEye(rOther.mEye), mLookAt(rOther.mLookAt), mRollAngle(rOther.mRollAngle), mUp(rOther.mUp), mU(rOther.mU), mV(rOther.mV), mW(rOther.mW), mExposureTime(rOther.mExposureTime)
  {
    return;
  }

  Camera		&Camera::operator=(Camera const &rOther)
  {
    if (this != &rOther)
      {
	mEye = rOther.mEye;
	mLookAt = rOther.mLookAt;
	mRollAngle = rOther.mRollAngle;
	mUp = rOther.mUp;
	mU = rOther.mU;
	mV = rOther.mV;
	mW = rOther.mW;
	mExposureTime = rOther.mExposureTime;
      }
    return (*this);
  }

  void			Camera::SetEye(Maths::Point const &rEye)
  {
    mEye = rEye;
  }

  void			Camera::SetEye(long double rX, long double rY, long double rZ)
  {
    mEye = Maths::Point(rX, rY, rZ);
  }

  void			Camera::SetLookAt(Maths::Point const &rLookAt)
  {
    mLookAt = rLookAt;
  }

  void			Camera::SetLookAt(long double rX, long double rY, long double rZ)
  {
    mLookAt = Maths::Point(rX, rY, rZ);
  }

  void			Camera::SetUpVector(Maths::Vector const &rVector)
  {
    mUp = rVector;
  }

  void			Camera::SetUpVector(long double rX, long double rY, long double rZ)
  {
    mUp = Maths::Vector(rX, rY, rZ);
  }

  void			Camera::SetRoll(long double rRollAngle)
  {
    mRollAngle = rRollAngle;
  }

  void			Camera::SetExposureTime(long double rExposureTime)
  {
    mExposureTime = rExposureTime;
  }

  void			Camera::ComputeUVW(void)
  {
    mW = mEye - mLookAt;
    mW.Normalize();
    mU = mUp ^ mW;
    mU.Normalize();
    mV = mW ^ mU;
    if (mEye[0] == mLookAt[0] && mEye[2] == mLookAt[2] && mEye[1] > mLookAt[1])
      {
	mU = Maths::Vector(0, 0, 1);
	mV = Maths::Vector(1, 0, 0);
	mW = Maths::Vector(0, 1, 0);
      }
    if (mEye[0] == mLookAt[0] && mEye[2] == mLookAt[2] && mEye[1] < mLookAt[1])
      {
	mU = Maths::Vector(1, 0, 0);
	mV = Maths::Vector(0, 0, 1);
	mW = Maths::Vector(0, -1, 0);
      }
  }

  Camera::~Camera(void)
  {
    return;
  }
};
